package com.superlistaportable.resultList;

import java.util.ArrayList;

import android.content.Intent;
import android.os.Bundle;

public class ResultListModel {
	ArrayList<String> itemsWithStock;
	float[] totals;
	public ResultListModel(Intent i){
		Bundle extras = i.getExtras();
		if (extras != null) {
        	itemsWithStock = extras.getStringArrayList("itemsWithStock");
        	totals = extras.getFloatArray("totals");
        }
    }
	
	public ArrayList<String> getResultList(){
		ArrayList<String> resultList = new ArrayList<String>();
		for (int i = 0; i < itemsWithStock.size(); i++) {
			resultList.add(itemsWithStock.get(i) + " $" + String.format( "%.2f", totals[i] ));
		}
		
		return resultList;
	}
	
	public float getTotal(){
		float total = 0.0f;
		for (int i = 0; i < totals.length; i++) {
			total += totals[i];
		}
		return total;
	}
	
	public String getListaItems(){
		String listaItems = "";
		for(int i=0;i< itemsWithStock.size();i++){
			listaItems = listaItems+itemsWithStock.get(i)+ "$" + String.format( "%.2f", totals[i] )+","+"\n";
		}
		listaItems = listaItems+"\n" + String.format( "Total $%.2f", getTotal() );
		return listaItems;
	}
}
